<%@ page import="org.opencms.jsp.CmsJspActionElement"%>
<%@ page import="org.opencms.file.CmsResource"%>
<%@ page import="org.opencms.jsp.CmsJspNavElement"%>
<%@ page import="org.opencms.file.CmsPropertyDefinition"%>
<%@ page import="java.util.*" %>
<%@ page import="org.opencms.file.CmsResource,
	org.opencms.jsp.CmsJspActionElement,
	org.opencms.jsp.CmsJspNavElement,
	org.opencms.file.CmsPropertyDefinition,
	com.dcampus.contentmodels.CmsTemplateResolver,
	java.util.List,
	java.util.Iterator"%><% 
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
String uri = cms.getRequestContext().getUri();
String site = null;		
try{
	site = CmsTemplateResolver.getPath(cms.getCmsObject(), "dc-site");
}catch(Exception e){
	//IGNORE
}

if(site == null)
	site = CmsTemplateResolver.getSite(uri);
String rootcolumn = uri.substring(0, uri.indexOf("/", site.length() + 1) + 1);
String menuTitle = cms.property(CmsPropertyDefinition.PROPERTY_TITLE, rootcolumn);
%>
<h3><%=menuTitle %></h3>
<%
String menu = buildMenu(cms, rootcolumn, cms.link(uri), null, true);
if(menu != null)
    out.print(menu);
%><%!
private static String buildMenu(CmsJspActionElement cms, String folder, String path, String appenditem, boolean root){
	StringBuffer buffer = new StringBuffer();
	if(root)
		buffer.append("<ul>");
	if(appenditem != null)
		buffer.append(appenditem);
	
	List list = cms.getNavigation().getNavigationForFolder(folder);
	if(list.size() > 0){
		if(!root)
		    buffer.append("<!--[if gte IE 7]><!--></a><!--<![endif]-->"
				+ "<!--[if lte IE 6]><table><tr><td><![endif]-->"
				+ "<ul>");
		
		Iterator i = list.iterator();
		while (i.hasNext()){
		    CmsJspNavElement ne = (CmsJspNavElement)i.next();		
		    if(!ne.isFolderLink())
		    	continue;
		    
		    boolean newwin = "true".equalsIgnoreCase(ne.getProperty(CmsPropertyDefinition.PROPERTY_NAVNEWWIN));
		    String link = cms.link(ne.getResourceName());
		    buffer.append("<li");
		    if(path != null && path.startsWith(link))
		    	buffer.append(" class=\"selected\"");
		    buffer.append("><a href=\"");
		    buffer.append(link);
		    buffer.append("\"");
		    buffer.append(newwin ? " target=\"_blank\"" : "");
		    buffer.append(">");
		    String text = ne.getProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT);
		    if(text == null || "".equals(text.trim())){
		        text = ne.getProperty(CmsPropertyDefinition.PROPERTY_TITLE);
		    }
		    if(text == null){
		        text = ne.getFileName();
		    }else{
		        text = text.trim();
		    }
		    buffer.append(text);
		    String submenu = buildMenu(cms, ne.getResourceName(), path, null, false);
		    buffer.append(submenu == null ? "</a>" : submenu);
		    buffer.append("</li>");
		}
		if(!root)
		    buffer.append("</ul>" + "<!--[if lte IE 6]></td></tr></table></a><![endif]-->");	
	}

	if(root)
		buffer.append("</ul>");

	return buffer.length() == 0 ? null : buffer.toString();
}
%>
